package liumengbaio.lolzhangyoubao.Activity.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.PopupWindow;

import java.util.zip.Inflater;

import liumengbaio.lolzhangyoubao.Activity.utils.GoodView;
import liumengbaio.lolzhangyoubao.R;

/**
 * 精彩专栏界面--Web的页面
 * 与视频界面--的Web页面，布局共用
 * Created by lanouhn on 16/9/18.
 */
public class MoreSpecialThirdActivity extends AppCompatActivity implements View.OnClickListener {

    private String id;
    private WebView mWebView;
    private GoodView mGoodView;
    private PopupWindow mPopupWindow;
    private ImageView back, more, good, goodChecked, bad, badChecked;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.video_third_body);
        initView();
        initData();
        initEvent();
    }

    private void initView() {
        mGoodView = new GoodView(this);

        mWebView = (WebView) findViewById(R.id.video_third_wb);
        back = (ImageView) findViewById(R.id.video_third_badyBack);
        more = (ImageView) findViewById(R.id.video_third_badyMore);
        good = (ImageView) findViewById(R.id.video_good);
        bad = (ImageView) findViewById(R.id.video_bad);
        goodChecked = (ImageView) findViewById(R.id.video_goodChecked);
        badChecked = (ImageView) findViewById(R.id.video_badChecked);
    }

    private void initData() {
        Intent intent = getIntent();
        id = intent.getStringExtra("id");
        String url = "http://api.lol.zhangyoubao.com/mobiles/item/" + id + "?v_=400901&token=1285c08b612411d" +
                "0bfc35f213eb5d92a73&user_id=15863305&size=middle&t=1474187539";
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        mWebView.loadUrl(url);
    }

    private void initEvent() {
        bad.setOnClickListener(this);
        good.setOnClickListener(this);
        more.setOnClickListener(this);
        back.setOnClickListener(this);
        badChecked.setOnClickListener(this);
        goodChecked.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.video_good:
                good.setVisibility(View.INVISIBLE);
                goodChecked.setVisibility(View.VISIBLE);
                mGoodView.setImage(getResources().getDrawable(R.mipmap.video_third_goodup));
                mGoodView.show(v);
                bad.setEnabled(false);

                break;
            case R.id.video_bad:

                bad.setVisibility(View.INVISIBLE);
                badChecked.setVisibility(View.VISIBLE);
                good.setEnabled(false);
                break;
            case R.id.video_goodChecked:

                good.setVisibility(View.VISIBLE);
                goodChecked.setVisibility(View.INVISIBLE);
                bad.setEnabled(true);
                break;
            case R.id.video_badChecked:

                bad.setVisibility(View.VISIBLE);
                badChecked.setVisibility(View.INVISIBLE);
                good.setEnabled(true);
                break;
            case R.id.video_third_badyBack:

                finish();
                break;
            case R.id.video_third_badyMore:
                View view = getLayoutInflater().inflate(R.layout.video_popwindow, null);
                mPopupWindow = new PopupWindow(view, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
                mPopupWindow.showAsDropDown(more);
                view.setOnTouchListener(new View.OnTouchListener() {
                    @Override
                    public boolean onTouch(View v, MotionEvent event) {
                        if (mPopupWindow != null && mPopupWindow.isShowing()) {
                            mPopupWindow.dismiss();
                            mPopupWindow = null;
                        }
                        return false;
                    }
                });

                break;
//            case R.id.video_good:
//                break;
        }
    }
}
